<!DOCTYPE html>
<html>

<head>
	<title>小水滴</title>
	<meta name="keywords"  />
	<meta name="description" content="" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
	<!-- Custom Theme files 1280*559-->
  	<link href="/static/js/layui/css/layui.css" rel="stylesheet">
	<link href="/static/js/layui/css/form.css" rel="stylesheet">
	<!-- //Custom Theme files -->
	<!-- 青、赤、黄、白、黑 -->
  	<script src="/static/js/layui/layui.js"></script>
  	<script src="/static/js/common.js"></script>
	<style>
		.table{
			border-color: #5f5f5f;width: 95%;
		}
		.table .head td{
			font-weight: 700;
		}
		.table td{
			padding: 7px 10px;border-collapse: collapse;
			border: 1px solid rgb(238, 238, 238);
		}
	</style>
</head>

<body class="body-page">
	<div class="search layui-form" lay-filter="search">
		<div class="form-table">
			<div class="form-row">
				<div class="form-cell">
					<label>归属项目</label>
				</div>
				<div class="form-cell">
					<select name="projectId" lay-filter="projectId" lay-search="" lay-verify=""></select>
				</div>
				<div class="form-cell">
					<button class="layui-btn layui-btn-sm" id="fullScreen">全屏</button>
				</div>
			</div>
		</div>
	</div>
	<div class="grid">
		<table id="table" class="table">
			<tr class="head">
			</tr>
		</table>
	</div>
</body>
<script>
	var tableId = 'table'+c.uuid();
	var editArea = ['1000px', '500px'];

	$(function(){

		$('#fullScreen').click(function(){
			window.open("/html/project_view.html", "_blank");
		});

		$('#create').click(function(){
			c.window({
				area: editArea,
				content:'/html/user_add.html'
			});
		});

		$('#search').click(function(){
			reloadTable({where:c.putPrefix(form.val('search'),'user.')});
		});

		c.request('project/page',{page:1,limit:1000},function(resp){
			if( resp.code == 0 ){
				var ele = $('select[name="projectId"]');
				var list = resp.data.list;
				ele.empty();
				ele.append('<option value="">请选择或搜索</option>');
				for( var i=0 ; i<list.length ; i++ ){
					var row = list[i];
					ele.append('<option value="'+row.id+'">'+row.cname+'</option>');
				}
				form.render(ele);
			}else{
				c.message(resp.message);
			}
		});

		c.request('view/project',{page:1,limit:1000},function(resp){
			if( resp.code == 200 ){
				var d = resp.data;
				loadTableData(d);
			}else{
				c.message(resp.message);
			}
		});
	});

	function loadTableData(d){
		var cols = [
			{field:'cname',title:'项目简称'},
			{field:'taskName',title:'任务名称'},
			{field:'status',title:'任务状态'},
			{field:'yfs',title:'研发'},
			{field:'cs',title:'测试'},
			{field:'cp',title:'产品'},
			{field:'inManager',title:'经理'},
			{field:'startTime',title:'开始时间'},
			{field:'stopTime',title:'提测时间'},
			{field:'onlineTime',title:'上线时间'},
			{field:'remarks',title:'任务备注'}
		];
		loadTableHead(cols);
		for( var i=0 ; i<d.length ; i++ ){
			var tr = $('<tr></tr>');
			var row = d[i];

			for( var j=0 ; j<cols.length ; j++ ){
				var col = cols[j];
				tr.append('<td>'+getCellValue(row,col)+'</td>');
			}
			$('#table').append(tr);
		}
		
	}

	function loadTableHead(cols){
		for( var i=0 ; i<cols.length ; i++ ){
			var col = cols[i];
			$('#table .head').append('<td>'+col.title+'</td>');
		}
	}

	function getCellValue(row,col){
		var value = row[col.field];
		if( value == undefined || value == null ){
			return '';
		}else{
			if( col.field.endsWith('Time') ){
				value = value.substr(0,10);
			}
			return value;
		}
	}

	function reloadTable(queryParams){
		queryParams = queryParams ? queryParams : {};
		table.reloadData(tableId,queryParams,true);
	}

	function editRow(id){
		c.window({
			area: editArea,
			content:'/html/user_add.html?id='+id
		});
	}

	function deleteRow(id){
    	layer.confirm('确定要删除吗？', {icon: 3, title:'提示'}, function(index){
			c.request('user/delete',{id:id},function(resp){
				if( resp.code == 200 ){
					c.message('删除成功');
				}else{
					c.message(resp.message);
				}
				reloadTable();
			});
			layer.close(index);
		});
	}

	
</script>
</html>